import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:winkai/ui/discover/discover_child_page.dart';
import 'package:winkai/widget/keep_alive.dart';

class DiscoverController extends GetxController {
  late List<Widget> pages;
  late PageController pageController;
  int currentIndex = 0;

  @override
  void onInit() {
    super.onInit();
    pages = [
      keepAliveWrapper(const DiscoverChildPage(index: 0)),
      keepAliveWrapper(const DiscoverChildPage(index: 1)),
      keepAliveWrapper(const DiscoverChildPage(index: 2)),
    ];
    pageController = PageController(initialPage: currentIndex);
  }

  void selectPage(int index,{bool isSwitch=true}) {
    if(isSwitch){
      pageController.animateToPage(index,
          duration: const Duration(milliseconds: 400), curve: Curves.ease);
    }
    currentIndex = index;
    update();
  }
}
